var express = require('express')

var app = express()

var fs = require('fs')
var path = require('path')
var proxy = require('http-proxy-middleware');
var multiparty = require('multiparty');

app.get('/getlistdata', function(req, res, next) {
    res.contentType('json');
    // console.log(req.query);
    var R = req.query.R;
    var data = {
      code:0,
      data:[{name:"企业空间3.0--项目轻应用(第一次迭代)"+R}]
    };
    setTimeout(function(){
      res.send(data);
      res.end();
    },1000);
});
//文件上传测试
app.post("/projectFile/*",function(req,res,next){
    var form = new multiparty.Form({uploadDir: './test/'});
    form.parse(req,function(err,fields,files){
        if(err){
            res.send(err);
        }else{
            var file = files.file[0];
            var headers = file.headers;
            var type = headers['content-type'];
            type = type.split('/')[1];
            size = file.size/1000;
            size = size + "KB";
            var data = {
                id: Math.random(10000),
                fileExtension:type,
                fileName:file.originalFilename,
                fileKey:file.path,
                fileSize:file.size
            }
            res.send({code:0,data:[data]});
        }

    });
})



app.use(express.static(__dirname));
//代理 ， 测试ie8专用
app.use([
	'/task/*',
    '/project/*',
    '/logger/*',
    '/wc/*'
], proxy({
	target: 'http://121.42.30.191',
}))
.use([
    '/doc/doc/*'
], proxy({
    target: 'http://123.103.9.204:91',
}))

app.listen(4444, function() {
	console.log("====================");
	console.log('http://localhost:4444/Apps/dailyrecord/index.html, Ctrl+C to stop');
	console.log("====================");
})
